package com.enation.app.javashop.core.client.fallback.goods;

import com.enation.app.javashop.core.client.feignimpl.goods.GoodsClientFeignImpl;
import com.enation.app.javashop.core.handler.BaseFallbackFactory;
import com.enation.app.javashop.framework.database.WebPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.enation.app.javashop.framework.util.StringUtil;
import com.enation.app.javashop.model.goods.dos.CategoryDO;
import com.enation.app.javashop.model.goods.dos.GoodsDO;
import com.enation.app.javashop.model.goods.dto.GoodsQueryParam;
import com.enation.app.javashop.model.goods.vo.*;
import com.enation.app.javashop.model.security.ScanModuleDTO;
import com.enation.app.javashop.model.security.ScanResult;
import com.enation.app.javashop.model.trade.order.vo.OrderSkuVO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 商品相关熔断 fallback factory
 * @author kingapex
 * @version 1.0
 * @data 2022/5/28 14:15
 **/
@Component
public class GoodsClientFallbackFactory  extends BaseFallbackFactory<GoodsClientFeignImpl> {
    @Override
    protected GoodsClientFeignImpl fallback() {
        return new GoodsClientFallback();
    }

    /**
     * 商品相关熔断
     *
     * @author zh
     * @version v7.0
     * @date 18/9/27 下午2:37
     * @since v7.0
     */
    @Component
    public static class GoodsClientFallback implements GoodsClientFeignImpl {

        private final Logger logger = LoggerFactory.getLogger(getClass());

        @Override
        public List<BackendGoodsVO> newGoods(Integer length) {
            logger.error("获取最新商品错误");
            return null;
        }

        @Override
        public void underShopGoods(Long sellerId) {
            logger.error("下架店铺ID为" + sellerId + "的全部商品错误");
        }

        @Override
        public void updateGoodsGrade() {
            logger.error("更新商品好平率错误");
        }

        @Override
        public CacheGoods getFromCache(Long goodsId) {
            logger.error("缓存中查询商品ID为" + goodsId + "的信息错误");
            return null;
        }

        @Override
        public GoodsSkuVO getSku(Long skuId) {
            return null;
        }

        @Override
        public List<GoodsSelectLine> query(Long[] goodsIds) {
            logger.error("查询多个商品的基本信息错误");
            return null;
        }

        @Override
        public void checkSellerGoodsCount(Long[] goodsIds) {
            logger.error("判断商品是否都是某商家的商品错误");
        }

        @Override
        public List<Map<String, Object>> getGoodsAndParams(Long[] goodsIds) {
            logger.error("查询很多商品的信息和参数信息错误");
            return null;
        }

        @Override
        public List<GoodsDO> listGoods(Long sellerId) {
            logger.error("按销量查询若干条数据错误,商家ID为" + sellerId);
            return null;
        }

        @Override
        public GoodsSkuVO getSkuFromCache(Long skuId) {
            logger.error("缓存中查询sku ID为" + skuId + "信息错误");
            return null;
        }

        @Override
        public void updateCommentCount(Long goodsId, Integer num) {
            logger.error("更新商品ID为" + goodsId + "的评论数量错误");
        }


        @Override
        public void updateBuyCount(List<OrderSkuVO> list) {
            logger.error("更新商品的购买数量错误");
        }

        @Override
        public Integer queryGoodsCount() {
            logger.error("查询商品的总数量错误");
            return null;
        }

        @Override
        public List<Map<String,Object>> queryGoodsByRange(Long pageNo, Long pageSize) {
            logger.error("查询某范围的商品信息错误");
            return null;
        }

        @Override
        public GoodsSnapshotVO queryGoodsSnapShotInfo(Long goodsId) {
            logger.error("添加商品快照查询商品信息错误，商品Id为" + goodsId);
            return null;
        }

        @Override
        public WebPage list(GoodsQueryParam goodsQueryParam) {
            logger.error("查询商品列表错误");
            return null;
        }

        @Override
        public GoodsDO checkShipTemplate(Long templateId) {
            logger.error("校验商品模版是否使用错误");
            return null;
        }

        @Override
        public Integer getSellerGoodsCount(Long sellerId) {
            logger.error("查询店铺ID为" + sellerId + "正在售卖中的商品数量错误");
            return 0;
        }

        @Override
        public Integer queryGoodsCountByParam(Integer status, Long sellerId) {
            logger.error("查询店铺ID为" + sellerId + "正在售卖中的商品数量错误");
            return 0;
        }

        @Override
        public List<GoodsDO> queryDo(Long[] goodsIds) {
            logger.error("查询商品ID为" + goodsIds + "正在售卖中的商品数量错误");
            List<GoodsDO> goods = new ArrayList();
            return goods;
        }

        @Override
        public List<Map<String, Object>> getGoodsAndParams(Long sellerId) {
            logger.error("根基商家id为" + sellerId + "查询商家商品的信息和参数信息发生错误");
            List<Map<String, Object>> list = new ArrayList<>();
            return list;
        }

        @Override
        public CategoryDO getCategory(Long id) {
            logger.error("获取商品分类信息发生错误");
            return new CategoryDO();
        }


        @Override
        public void updateGoodsType(Long sellerId, String type) {
            logger.error("更新商家ID为" + sellerId + "的商品类型发生错误");
        }

        @Override
        public void updateGoodsSelfOperated(Long sellerId, Integer selfOperated) {
            logger.error("updateGoodsSelfOperated发生错误");
        }

        @Override
        public Integer queryGoodsCountForPageCreate() {
            logger.error("queryGoodsCountForPageCreate发生错误");
            return null;
        }

        @Override
        public Boolean checkExist(Long skuId) {
            logger.error("checkExist发生错误");
            return false;
        }

        @Override
        public List<GoodsDO> listPointGoods(Long shopId) {
            logger.error("查询商家ID为" + shopId + "的积分商品发生错误");
            List<GoodsDO> goods = new ArrayList<>();
            return goods;
        }

        @Override
        public List<GoodsSelectLine> querySkus(Long[] skuIds) {

            logger.error("查询sku发生异常，skuid集合为" + skuIds);

            return null;
        }

        @Override
        public List<GoodsSkuVO> listByGoodsId(Long goodsId) {

            logger.error("查询sku发生异常，商品ID为" + goodsId);

            return null;
        }

        @Override
        public List<GoodsDO> getSellerGoods(Long sellerId) {

            logger.error("查询某商家的商品异常，商家id为" + sellerId);
            return null;
        }

        @Override
        public List<CategoryVO> listAllChildren(Long parentId) {
            logger.error("查询商城分类异常，parentId为" + parentId);
            return null;
        }

        @Override
        public void createSkuExchangeScript(Long skuId, Long exchangeId, Double price, Integer point) {
            logger.error("生成积分兑换商品的脚本信息出错skuid" + skuId + "，exchangeId" + exchangeId + "，price" + price + "，point" + point);
        }

        @Override
        public void deleteSkuExchangeScript(Long skuId) {
            logger.error("删除积分兑换商品的脚本信息出错skuid" + skuId);
        }

        @Override
        public ScanResult scanModule(ScanModuleDTO scanModuleDTO) {
            logger.error("商品篡改数据扫描失败");
            return null;
        }

        @Override
        public void reSign() {
            logger.error("商品数据重新签名失败");
        }

        @Override
        public ScanResult scanSkuModule(ScanModuleDTO scanModuleDTO) {
            logger.error("sku篡改数据扫描失败");
            return null;
        }

        @Override
        public void reSignSku() {
            logger.error("sku数据重新签名失败");
        }

        @Override
        public void repair(Long goodsId) {
            logger.error("修复商品数据失败");
        }

        @Override
        public void repairSku(Long skuId) {
            logger.error("修复sku数据失败");
        }

        @Override
        public void changeSellerName(Long sellerId, String sellerName) {
            logger.error("修改商品的店铺名称出错");
        }

        @Override
        public List<Map<String, Object>> getGoods(Long[] goodsIds) {
            List<Long> items = new ArrayList<>();
            logger.error("获取商品信息错误,错误商品id为" + StringUtil.getIdStr(goodsIds, items));
            return new ArrayList<>();
        }
    }
}
